package au.edu.qut.bpm.genbinder;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.deckfour.xes.in.XParser;
import org.deckfour.xes.in.XesXmlParser;
import org.deckfour.xes.model.XLog;
import au.edu.qut.bpm.genbinder.genetic.evaluation.costmodels.TighteningMultiObjectiveCostModel;
import au.edu.qut.bpm.genbinder.genetic.genesis.LogRandomizedFactory;
import au.edu.qut.bpm.genbinder.models.Activity;
import au.edu.qut.bpm.genbinder.models.ConcreteEventLog;
import au.edu.qut.bpm.genbinder.ui.CostLandscapeVisualizer;
import au.edu.qut.bpm.genbinder.util.DiscreteLogConverter;
import au.edu.qut.bpm.genbinder.util.XESToLogConverter;

public class CostLandscapeTest {
	public static void main(String[] args) throws Exception {

		XParser parser = new XesXmlParser();
		List<XLog> l = parser.parse(new File("logs/CarInsuranceClaim(100Cases).xes"));
		XLog xlog = l.get(0);
		ConcreteEventLog log = XESToLogConverter.createLog(xlog);

		long BLOCK_DURATION = (1000 * 60);
		long zeroBlock =
				DiscreteLogConverter.timeToLowerBlock(log.getLogArrival(), 0, BLOCK_DURATION)
						* BLOCK_DURATION;
		log = DiscreteLogConverter.makeDiscrete(log, zeroBlock, BLOCK_DURATION);

		// Do a bit of randomized solution generation for now
		List<ConcreteEventLog> population = new ArrayList<ConcreteEventLog>();
		LogRandomizedFactory f = new LogRandomizedFactory(log);
		int total = 1000;
		for (int i = 0; i < total; i++) {
			if (i % 100 == 0) System.err.println(i+" / "+total);
			population.add(f.generateRandomCandidate(new Random()));
		}

		List<Activity> activitiesOfInterest =
				new ArrayList<Activity>(log.getAbstractLog().getActivities());
		Collections.shuffle(activitiesOfInterest);
		// Set<Activity> activitySet = new
		// HashSet<Activity>(activitiesOfInterest.subList(0, 1));

		// new CostLandscapeVisualizer(population, activitySet,
		// new TighteningMultiObjectiveCostModel());

		// Just inspect for one activity...
		System.err.println("Taking activity: "+activitiesOfInterest.get(0).getId());
		new CostLandscapeVisualizer(population, activitiesOfInterest.get(0),
				new TighteningMultiObjectiveCostModel());

	}
}
